package com.yfbao.horizon.schedule.tk.job;

import com.yfbao.horizon.schedule.tk.meter.DistributeLockMetrics;
import com.yfbao.horizon.schedule.tk.meter.LockThreadMetrics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

@Slf4j
@Component
public class DistributeLockTestJob {

    private Random random =new Random();

    @Scheduled(cron="0/20 * * * * ?")
    public void test(){
        long currentTimeMillis = System.currentTimeMillis();
        int sleepTime = random.nextInt(12);
        log.info("begin do job:"+sleepTime);
        log.warn("test log {} ,begin do job:{}","tttt",sleepTime);
        try {
            Thread.sleep(sleepTime*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        DistributeLockMetrics.successGet();
        DistributeLockMetrics.getCostTime(System.currentTimeMillis()-currentTimeMillis);
        LockThreadMetrics.addSummary(System.currentTimeMillis()-currentTimeMillis);
    }
}
